package com.bootdo.wx.api;

import com.bootdo.common.utils.R;
import com.bootdo.common.utils.StringUtils;
import com.bootdo.wx.domain.MemberPriceDO;
import com.bootdo.wx.service.OrderComService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * Created by HP on 2019/6/11.
 */
@Controller
@RequestMapping("/api/orderCom")
public class ApiOrderComController {

    @Autowired
    private OrderComService orderComService;


    /*
    * 我的余额
    * */
    @ResponseBody
    @RequestMapping("/getMemberCom")
    public R getMemberCom(@RequestBody Map<String,Object> paramMap) {
        try{
            if (!paramMap.containsKey("userId") || StringUtils.isBlank(paramMap.get("userId").toString())) {
                return R.error("参数错误");
            }
            Map<String,Object> map = orderComService.getMemberCom(paramMap);
            return R.ok().put("data", map);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error("查询失败");
        }
    }

    /*
    * 查看我的各种余额记录
    * type : "":所有，0：消费，1：提现，2：充值, 3：返利
    * */
    @ResponseBody
    @RequestMapping("/getMemberComList")
    public R getMemberComList(@RequestBody Map<String,Object> paramMap) {
        try{
            if (!paramMap.containsKey("userId") || StringUtils.isBlank(paramMap.get("userId").toString())
                    || !paramMap.containsKey("type")){
                return R.error("参数错误");
            }
            PageInfo<MemberPriceDO> list = orderComService.getMemberComList(paramMap);
            return R.ok().put("data", list);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error("查询失败");
        }
    }





}
